#include "EPSG/Group.h"

#include "EPSG/Node.h"

EPSG::Group::Group()
{

}

void EPSG::Group::render()
{
#ifdef _DEBUG
	//printf( "Rendering children of: %s\n", _name.data() );
#endif // _DEBUG

	std::vector<Node*>::iterator i;
	for( i = _children.begin(); i != _children.end(); ++i )
		(*i)->render();
}

bool EPSG::Group::addChild( Node* n )
{
	if( n == NULL )
		return false;

	n = n->setParent( this );
	if( n == NULL )
		return false;

	if( hasChild( n ) )
		return false;

	_children.push_back( n );
	return true;
}

bool EPSG::Group::hasChild( Node* n )
{
	std::vector<Node*>::iterator i;
	for( i = _children.begin(); i != _children.end(); ++i )
		if( (*i) == n )
			return true;

	return false;
}

bool EPSG::Group::delChild( Node* n )
{
	std::vector<Node*>::iterator i;
	for( i = _children.begin(); i != _children.end(); ++i )
	{
		if( (*i) == n )
		{
			_children.erase( i );
			return true;
		}
	}
	return false;
}

EPSG::Node* EPSG::Group::getChild( int index )
{
	if( index < (int)_children.size() )
		return _children.at( index );

	return NULL;
}

void EPSG::Group::print()
{
	Node::print();
	std::vector<Node*>::iterator i;
	for( i = _children.begin(); i != _children.end(); ++i )
		(*i)->print();
}